package com.example.blog.model;


import com.example.blog.enumcode.EnumCode;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
public class  Result<T> {
    private String errMsg;
    private int code;
    private T data;

    public static <T> Result success(T data) {
        Result result = new Result();
        result.setCode(EnumCode.SUCCESS.getCode());
        result.setData(data);
        result.setErrMsg("");
        return result;
    }
    public static <T> Result failure(String errMsg) {
        Result result = new Result();
        result.setCode(EnumCode.FAILURE.getCode());
        result.setErrMsg(errMsg);
        return result;
    }
    public static <T> Result failure(int code,String errMsg) {
        Result result = new Result();
        result.setCode(EnumCode.NULLRESOURCE.getCode());
        result.setErrMsg(errMsg);
        return result;
    }
    public static <T> Result nologin(T data) {
        Result result = new Result();
        result.setCode(EnumCode.NOLOGIN.getCode());
        //result.setData(data);
        result.setErrMsg("未登录!!");
        return result;
    }
    public static <T> Result nologin(String errMsg,int code) {
        Result result = new Result();
        result.setCode(code);
        //result.setData(data);
        result.setErrMsg(errMsg);
        return result;
    }
}
